/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */

package com.ykht.proj.activity.controller.c;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ykht.proj.activity.entity.CnActivityGoods;
import com.ykht.proj.activity.entity.CnActivityMall;
import com.ykht.proj.activity.service.CnActivityGoodsService;
import com.ykht.proj.activity.service.CnActivityMallService;
import com.ykht.proj.activity.vo.ActivityMallType0Vo;
import com.ykht.proj.common.core.util.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 活动商品
 *
 * @author proj code generator
 * @date 2020-12-25 15:21:19
 */
@RestController
@AllArgsConstructor
@RequestMapping("c/actGoods" )
@Api(value = "cnactivitygoods", tags = "c端活动商品管理")
public class ActivityGoodsController {

    private final  CnActivityGoodsService cnActivityGoodsService;
    private final CnActivityMallService cnActivityMallService;


	@ApiOperation(value = "活动推荐", notes = "活动推荐")
	@GetMapping("/actList" )
	public R<ActivityMallType0Vo> actPage(CnActivityGoods cnActivityGoods) {
		ActivityMallType0Vo vo = new ActivityMallType0Vo();

		List<CnActivityGoods> list = cnActivityGoodsService.list( Wrappers.lambdaQuery(CnActivityGoods.class)
				.eq(CnActivityGoods::getActMallId,cnActivityGoods.getActMallId())
				.eq(CnActivityGoods::getType,0)
				.eq(CnActivityGoods::getDisplay,0)
				.orderByAsc(CnActivityGoods::getSort));
		vo.setGoods(list);
		vo.setCnActivityMall(cnActivityMallService.getById(cnActivityGoods.getActMallId()));
		return R.ok(vo);
	}
	@ApiOperation(value = "分页活动更多好礼----分页", notes = "活动更多好礼----分页")
	@GetMapping("/actMorePage" )
	public R<Page<CnActivityGoods>> actMorePage(Page page,CnActivityGoods cnActivityGoods) {
		return R.ok(cnActivityGoodsService.page(page, Wrappers.lambdaQuery(CnActivityGoods.class)
				.eq(CnActivityGoods::getActMallId,cnActivityGoods.getActMallId())
				.eq(CnActivityGoods::getType,1)//更多好礼
				.eq(CnActivityGoods::getDisplay,0)//上架
				.orderByAsc(CnActivityGoods::getSort)));
	}

	@ApiOperation(value = "分页活动更多好礼----不分页", notes = "活动更多好礼----不分页")
	@GetMapping("/actMore" )
	public R<List<CnActivityGoods>> actMore(CnActivityGoods cnActivityGoods) {
		return R.ok(cnActivityGoodsService.list( Wrappers.lambdaQuery(CnActivityGoods.class)
				.eq(CnActivityGoods::getActMallId,cnActivityGoods.getActMallId())
				.eq(CnActivityGoods::getType,1)//更多好礼
				.eq(CnActivityGoods::getDisplay,0)//上架
				.orderByAsc(CnActivityGoods::getSort)));
	}


    /**
     * 通过id查询活动商品
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询商品详情")
    @GetMapping("/{id}" )
    public R<CnActivityGoods> getById(@PathVariable("id" ) Long id) {
        return R.ok(cnActivityGoodsService.getById(id));
    }

}
